<?php $this->load->view('_header'); ?>
<?php echo link_tag('/assets/css/frontend/question.css'); ?>
<div id="main-content">
    <table>
        <?php foreach ($questions as $k => $q): ?>
            <tr style="background-color: #f0f0f0;">
                <td rowspan="3" style="text-align: center;width: 100px;"><?php echo $q->author; ?></td>
                <td style="font-weight: bold;"><?php echo $q->title; ?></td>
            </tr>
            <tr>
                <td>
                <?php echo $q->content; ?>
                <?php if ($anwsers = $this->question->getAnwsers($q->id)): ?>
                <?php foreach ($anwsers as $a): ?>
                        <p style="border-top:1px solid #ededed;margin: 5px 0px;padding: 5px;"><strong><?php echo $a->author; ?>解答:</strong><?php echo $a->content; ?></p>
                <?php endforeach; ?>
                <?php endif; ?>
                    </td>
                </tr>
                <tr style="background-color: #f0f0f0;">
                    <td>发表时间：<?php echo $q->created_at; ?></td>
                </tr>
        <?php endforeach; ?>
                    </table>

                    <div class="page_links"><?php echo $page_links; ?></div>

                    <div class="form">
                        <div id="callbackinfo" style="padding: 20px; color: green;"></div>
                        <form action="/index.php?c=question&m=add" method="post">
                            <label for="author">您的称呼</label>
                            <input type="text" name="author" value=""/>
                            <br/><br/>
                            <label for="title">标&nbsp;&nbsp;&nbsp;&nbsp;题</label>
                            <input type="text" name="title" value=""/>
                            <br/><br/>
                            <label for="content">问&nbsp;&nbsp;&nbsp;&nbsp;题</label>
                            <textarea name="content" id="content" cols="45" rows="10"></textarea>
                            <br/><br/>
                            <div class="form_btn">
                                <input type="submit" name="submit" value="提交问题"/>
                            </div>
                        </form>
                    </div>
                </div>
                <script type="text/javascript">
                    $(function(){
                        $(".form input[type=submit]").click(function(event){
                            event.preventDefault();
                            var data = $(".form form:eq(0)").serialize();
                            $.ajax({
                                type:"post",
                                url: "/index.php?c=question&m=add",
                                data: data+"&submit=submit",
                                dataType: "json",
                                success: function(msg){
                                    switch (msg['statu']){
                                        case 1:
                                            $(".form #callbackinfo").html(msg["detail"]).css({"color":"green"});
                                            break;
                                        case 0:
                                            $(".form #callbackinfo").html(msg["detail"]).css({"color":"red"});
                                            break;
                                        default:
                                            $(".form #callbackinfo").html("未知错误！").css({"color":"red"});
                                            break;
                                    }
                                }
                            });
                        });
                    });
                </script>
<?php $this->load->view('_footer'); ?>
